#pragma once 
#include <iostream>
#include <string>

#define Die(code)   \
    do              \
    {               \
        exit(code); \
    } while (0)
#define CONV(v) (struct sockaddr *)(v)


enum
{
    USAGE_ERR = 1,
    SOCKET_ERR,
    BIND_ERR,
    LISTEN_ERR,
    ACCEPT_ERR,
    CONNECT_ERR,
};

const int gdefaultsockfd = -1;
const int gbacklog = 8;

// 去除换行符
bool ParseOneLine(std::string& str, std::string *out, const std::string &seq)
{
    auto pos = str.find(seq);
    if(pos == std::string::npos) return false;
    *out = str.substr(0, pos);
    str.erase(0, pos + seq.size());
    return true;
}

bool SplitString(const std::string &header,const std::string &HeaderLineSep,std::string *key,std::string *value)
{
    auto pos = header.find(HeaderLineSep);
    if(pos == std::string::npos) return false;
    *key = header.substr(0,pos);
    *value = header.substr(pos+HeaderLineSep.size());
    return true;
}